# 随机选择100个视频出来。

from openpyxl import Workbook 
from openpyxl import load_workbook
import os
import random

origin_dir = "origin_data/"
rawdata_dir = "rawdata/"

random_times = 100 # 100 files

files =  os.listdir(origin_dir)
for file in files:
    wb = load_workbook(origin_dir + "/" + file)
    ws = wb.active
    
    new_wb = Workbook()
    new_ws = new_wb.active

    # 复制标题
    for col in range(1, ws.max_column + 1):
        new_ws.cell(1, col).value = ws.cell(1, col).value

    # 复制数据
    # 获取100个不相等得随机数
    row_list = []
    while len(row_list) < random_times:
        row = random.randint(2, ws.max_row) # skip title
        if row not in row_list:
            row_list.append(row)
    
    # 根据随机的row去读取文件内容
    start_row = 2
    for row in row_list:
        for col in range(1, ws.max_column + 1):
            new_ws.cell(start_row, col).value = ws.cell(row, col).value
        start_row += 1

    # 保存文件
    new_wb.save(rawdata_dir + "/" + file)
print("[INFO] 选择100个视频成功！")
